<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    #canvas {
      border: 1px solid;
    }
  </style>
</head>

<body>
  <canvas width="340" height="400" id="canvas"> 请升级你的服务器 </canvas>
  <canvas width="340" height="400" id="canvas2" style="margin-left: 30px"> 请升级你的服务器 </canvas>
  <script>
    var canvas = document.querySelector("#canvas");
    var context = canvas.getContext("2d");
    var canvas2 = document.querySelector("#canvas2");
    var context2 = canvas2.getContext("2d");
    var diffList = [
      { x1: '279', y1: '144', x2: '331', y2: '184', isFound: false },
      { x1: '161', y1: '6', x2: '238', y2: '49', isFound: false },
      { x1: '158', y1: '395', x2: '191', y2: '416', isFound: false },
      { x1: '32', y1: '133', x2: '89', y2: '189', isFound: false },
    ]
    var image = new Image()
    image.src = './diff.jpg'
    image.onload = function () {
      canvas.height = image.height
      canvas2.height = image.height
      context.drawImage(image, 0, 0);
      context2.drawImage(image, -400, 0);
    }
    canvas2.onclick = function (event) {
      diffList.forEach(item => {
        if (event.offsetX > item.x1 && event.offsetX < item.x2 && event.offsetY > item.y1 && event.offsetY < item.y2) {
          context2.rect(item.x1, item.y1, item.x2 - item.x1, item.y2 - item.y1);
          context2.strokeStyle = '#f00';
          context2.stroke();
          item.isFound = true;
          var isFinished = diffList.some(item => {
            return item.isFound === false
          })
          setTimeout(function () {
            if (!isFinished) alert('恭喜你,全部找出!')
          }, 0)
        }
      })
    }
  </script>
</body>

</html>